package com.powernode.vo;

import com.powernode.result.CodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 统一响应前端对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class HttpResult implements Serializable {
    //响应码
    private int code;
    //响应消息
    private String msg;
    //响应具体数据
    private Object data;

    public static HttpResult SUCCESS() {
        return HttpResult.builder()
                .code(CodeEnum.SUCCESS.getCode())
                .msg(CodeEnum.SUCCESS.getMsg())
                .build();
    }

    public static HttpResult SUCCESS(Object data) {
        return HttpResult.builder()
                .code(CodeEnum.SUCCESS.getCode())
                .msg(CodeEnum.SUCCESS.getMsg())
                .data(data)
                .build();
    }

    public static HttpResult SUCCESS(String msg, Object data) {
        return HttpResult.builder()
                .code(CodeEnum.SUCCESS.getCode())
                .msg("秒杀正在进行中")
                .data(data)
                .build();
    }

    /**
     * 默认error
     * @return : -1 | 秒杀失败
     */
    public static HttpResult ERROR() {
        return HttpResult.builder()
                .code(CodeEnum.ERROR.getCode())
                .msg(CodeEnum.ERROR.getMsg())
                .build();
    }

    public static HttpResult ERROR(CodeEnum codeEnum) {
        return HttpResult.builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getMsg())
                .build();
    }

    public static HttpResult ERROR(String msg) {
        return HttpResult.builder()
                .code(CodeEnum.ERROR.getCode())
                .msg(msg)
                .build();
    }

}
